#pragma once
#include <QtConcurrent/QtConcurrent>
#include "qglobal.h"
#include <iostream>

namespace PikaChess {
/** 选边 */
constexpr quint8 RED { 0 }, BLACK { 7 }, OPP_SIDE { 7 };

/** 棋子种类 */
constexpr quint8 ROOK { 0 }, KNIGHT { 1 }, CANNON { 2 }, BISHOP { 3 };
constexpr quint8 PAWN { 4 }, ADVISOR { 5 }, KING { 6 };

/** 空棋子 */
constexpr quint8 EMPTY { 14 };
/** 所有的棋子类型，上层为滑动棋子，下层为跳跃棋子 */
constexpr quint8 RED_ROOK { 0 }, RED_KNIGHT { 1 }, RED_CANNON { 2 }, RED_BISHOP { 3 };
constexpr quint8 RED_PAWN { 4 }, RED_ADVISOR { 5 }, RED_KING { 6 };
constexpr quint8 BLACK_ROOK { 7 }, BLACK_KNIGHT { 8 }, BLACK_CANNON { 9 }, BLACK_BISHOP { 10 };
constexpr quint8 BLACK_PAWN { 11 }, BLACK_ADVISOR { 12 }, BLACK_KING { 13 };

/** 定义先行棋的分数 */
constexpr qint16 ADVANCED_SCORE { 3 };
/** 定义赢棋和棋输棋的分数 */
constexpr qint16 MATE_SCORE { 10000 }, DRAW_SCORE { 20 }, LOSS_SCORE { -10000 };
/** 长将判负的分值，在该值之内则不写入置换表 */
constexpr qint16 BAN_SCORE_MATE { 9500 }, BAN_SCORE_LOSS { -9500 };
/** 搜索出赢棋和输棋的分值界限，超出此值就说明已经搜索出杀棋了 */
constexpr qint16 WIN_SCORE { 9000 }, LOST_SCORE { -9000 };

/** 搜索状态机的阶段 */
constexpr quint8 PHASE_HASH { 0 };
constexpr quint8 PHASE_CAPTURE_GEN { 1 };
constexpr quint8 PHASE_CAPTURE { 2 };
constexpr quint8 PHASE_KILLER1 { 3 };
constexpr quint8 PHASE_KILLER2 { 4 };
constexpr quint8 PHASE_NOT_CAPTURE_GEN { 5 };
constexpr quint8 PHASE_REST { 6 };

/** MVV/LVA Most Valuable Victim Least Valuable Attacker
 *  每种子力的MVVLVA价值，车马炮象兵士将 */
constexpr qint8 MVVLVA[14] { 50, 20, 20, 2, 5, 2, 100,
                            50, 20, 20, 2, 5, 2, 100 };

/** 置换表的大小 */
constexpr quint32 HASH_SIZE { 1 << 23 };
/** 置换表掩码 */
constexpr quint32 HASH_MASK { HASH_SIZE - 1 };

/** 走法类型 */
constexpr quint8 HASH_ALPHA { 0 }, HASH_BETA { 1 }, HASH_PV { 2 };

/** 空着裁剪标志 */
constexpr bool NO_NULL { false };

/** 子力的位置分数 */
constexpr qint16 VALUE[14][90] {
{ // 车
    206,208,207,213,214,213,207,208,206,
    206,212,209,216,233,216,209,212,206,
    206,208,207,214,216,214,207,208,206,
    206,213,213,216,216,216,213,213,206,
    208,211,211,214,215,214,211,211,208,
    208,212,212,214,215,214,212,212,208,
    204,209,204,212,214,212,204,209,204,
    198,208,204,212,212,212,204,208,198,
    200,208,206,212,200,212,206,208,200,
    194,206,204,212,200,212,204,206,194,
},
{ // 马
    90, 90, 90, 96, 90, 96, 90, 90, 90,
    90, 96,103, 97, 94, 97,103, 96, 90,
    92, 98, 99,103, 99,103, 99, 98, 92,
    93,108,100,107,100,107,100,108, 93,
    90,100, 99,103,104,103, 99,100, 90,
    90, 98,101,102,103,102,101, 98, 90,
    92, 94, 98, 95, 98, 95, 98, 94, 92,
    93, 92, 94, 95, 92, 95, 94, 92, 93,
    85, 90, 92, 93, 78, 93, 92, 90, 85,
    88, 85, 90, 88, 90, 88, 90, 85, 88,
},
{ // 炮
   100,100, 96, 91, 90, 91, 96,100,100,
    98, 98, 96, 92, 89, 92, 96, 98, 98,
    97, 97, 96, 91, 92, 91, 96, 97, 97,
    96, 99, 99, 98,100, 98, 99, 99, 96,
    96, 96, 96, 96,100, 96, 96, 96, 96,
    95, 96, 99, 96,100, 96, 99, 96, 95,
    96, 96, 96, 96, 96, 96, 96, 96, 96,
    97, 96,100, 99,101, 99,100, 96, 97,
    96, 97, 98, 98, 98, 98, 98, 97, 96,
    96, 96, 97, 99, 99, 99, 97, 96, 96,
},
{ // 象
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0, 20,  0,  0,  0, 20,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
    18,  0,  0,  0, 23,  0,  0,  0, 18,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0, 20,  0,  0,  0, 20,  0,  0,
},
{ // 兵
     9,  9,  9, 11, 13, 11,  9,  9,  9,
    19, 24, 34, 42, 44, 42, 34, 24, 19,
    19, 24, 32, 37, 37, 37, 32, 24, 19,
    19, 23, 27, 29, 30, 29, 27, 23, 19,
    14, 18, 20, 27, 29, 27, 20, 18, 14,
     7,  0, 13,  0, 16,  0, 13,  0,  7,
     7,  0,  7,  0, 15,  0,  7,  0,  7,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
},
{ // 士
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0, 20,  0, 20,  0,  0,  0,
     0,  0,  0,  0, 23,  0,  0,  0,  0,
     0,  0,  0, 20,  0, 20,  0,  0,  0,
},
{ // 将
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  1,  1,  1,  0,  0,  0,
     0,  0,  0,  2,  2,  2,  0,  0,  0,
     0,  0,  0, 11, 15, 11,  0,  0,  0,
},
// 下面是黑方的部分
{
   194,206,204,212,200,212,204,206,194,
   200,208,206,212,200,212,206,208,200,
   198,208,204,212,212,212,204,208,198,
   204,209,204,212,214,212,204,209,204,
   208,212,212,214,215,214,212,212,208,
   208,211,211,214,215,214,211,211,208,
   206,213,213,216,216,216,213,213,206,
   206,208,207,214,216,214,207,208,206,
   206,212,209,216,233,216,209,212,206,
   206,208,207,213,214,213,207,208,206,
},
{
    88, 85, 90, 88, 90, 88, 90, 85, 88,
    85, 90, 92, 93, 78, 93, 92, 90, 85,
    93, 92, 94, 95, 92, 95, 94, 92, 93,
    92, 94, 98, 95, 98, 95, 98, 94, 92,
    90, 98,101,102,103,102,101, 98, 90,
    90,100, 99,103,104,103, 99,100, 90,
    93,108,100,107,100,107,100,108, 93,
    92, 98, 99,103, 99,103, 99, 98, 92,
    90, 96,103, 97, 94, 97,103, 96, 90,
    90, 90, 90, 96, 90, 96, 90, 90, 90,
},
{
    96, 96, 97, 99, 99, 99, 97, 96, 96,
    96, 97, 98, 98, 98, 98, 98, 97, 96,
    97, 96,100, 99,101, 99,100, 96, 97,
    96, 96, 96, 96, 96, 96, 96, 96, 96,
    95, 96, 99, 96,100, 96, 99, 96, 95,
    96, 96, 96, 96,100, 96, 96, 96, 96,
    96, 99, 99, 98,100, 98, 99, 99, 96,
    97, 97, 96, 91, 92, 91, 96, 97, 97,
    98, 98, 96, 92, 89, 92, 96, 98, 98,
   100,100, 96, 91, 90, 91, 96,100,100,
},
{
     0,  0, 20,  0,  0,  0, 20,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
    18,  0,  0,  0, 23,  0,  0,  0, 18,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0, 20,  0,  0,  0, 20,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
},
{
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     7,  0,  7,  0, 15,  0,  7,  0,  7,
     7,  0, 13,  0, 16,  0, 13,  0,  7,
    14, 18, 20, 27, 29, 27, 20, 18, 14,
    19, 23, 27, 29, 30, 29, 27, 23, 19,
    19, 24, 32, 37, 37, 37, 32, 24, 19,
    19, 24, 34, 42, 44, 42, 34, 24, 19,
     9,  9,  9, 11, 13, 11,  9,  9,  9,
},
{
     0,  0,  0, 20,  0, 20,  0,  0,  0,
     0,  0,  0,  0, 23,  0,  0,  0,  0,
     0,  0,  0, 20,  0, 20,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
},
{
     0,  0,  0, 11, 15, 11,  0,  0,  0,
     0,  0,  0,  2,  2,  2,  0,  0,  0,
     0,  0,  0,  1,  1,  1,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
     0,  0,  0,  0,  0,  0,  0,  0,  0,
}};
}
